package com.desmond.squarecamera;

import ohos.utils.Parcel;
import ohos.utils.Sequenceable;

public class ImageParameters implements Sequenceable {

    public boolean mIsPortrait;

    public int mDisplayOrientation;
    public int mLayoutOrientation;

    public int mCoverHeight;
    public int mCoverWidth;
    public int mPreviewHeight;
    public int mPreviewWidth;

    @Override
    public boolean marshalling(Parcel dest) {

        return dest.writeByte((byte) (mIsPortrait ? 1 : 0))
                && dest.writeInt(mDisplayOrientation)
                && dest.writeInt(mLayoutOrientation)
                && dest.writeInt(mCoverHeight)
                && dest.writeInt(mCoverWidth)
                && dest.writeInt(mPreviewHeight)
                && dest.writeInt(mPreviewWidth);
    }

    @Override
    public boolean unmarshalling(Parcel in) {

        mIsPortrait = in.readByte() == 1;

        mDisplayOrientation = in.readInt();
        mLayoutOrientation = in.readInt();

        mCoverHeight = in.readInt();
        mCoverWidth = in.readInt();
        mPreviewHeight = in.readInt();
        mPreviewWidth = in.readInt();

        return true;
    }

    public int calculateCoverWidthHeight() {
        return Math.abs(mPreviewHeight - mPreviewWidth) / 2;
    }

    public int getAnimationParameter() {
        return mIsPortrait ? mCoverHeight : mCoverWidth;
    }

    public boolean isPortrait() {
        return mIsPortrait;
    }

    public ImageParameters createCopy() {
        ImageParameters imageParameters = new ImageParameters();

        imageParameters.mIsPortrait = mIsPortrait;
        imageParameters.mDisplayOrientation = mDisplayOrientation;
        imageParameters.mLayoutOrientation = mLayoutOrientation;

        imageParameters.mCoverHeight = mCoverHeight;
        imageParameters.mCoverWidth = mCoverWidth;
        imageParameters.mPreviewHeight = mPreviewHeight;
        imageParameters.mPreviewWidth = mPreviewWidth;

        return imageParameters;
    }

    public String getStringValues() {
        return "is Portrait: " + mIsPortrait + ","
                + "\ncover height: " + mCoverHeight + " width: " + mCoverWidth
                + "\npreview height: " + mPreviewHeight + " width: " + mPreviewWidth;
    }
}
